package com.ctsi.uaa.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ctsi.common.util.Search;
import com.ctsi.uaa.service.IOnlineUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/10 11:04
 */
@Service
@RequiredArgsConstructor
public class OnlineUserServiceImpl implements IOnlineUserService {

    private final RedisTokenStore redisTokenStore;

    @Override
    public IPage<OAuth2AccessToken> onlineUser(Search search) {
        List<OAuth2AccessToken> collect = new ArrayList<>(redisTokenStore.findTokensByClientId("mars"));
        Page<OAuth2AccessToken> oAuth2AccessTokenPage = new Page<>();
        oAuth2AccessTokenPage.setRecords(collect);
        oAuth2AccessTokenPage.setTotal(collect.size());
        oAuth2AccessTokenPage.setCurrent(search.getCurrent());
        oAuth2AccessTokenPage.setSize(search.getSize());
        return oAuth2AccessTokenPage;
    }
}
